//
//  JSQMessageData.m
//  Conversation
//
//  Created by C_HAO on 15/9/28.
//  Copyright © 2015年 CHAOO. All rights reserved.
//

#import "JSQChatMessageData.h"
#import "JSQMessages.h"

@implementation JSQChatMessageData

- (instancetype)init {
    self = [super init];
    if (self) {

        JSQMessagesBubbleImageFactory *bubbleFactory = [[JSQMessagesBubbleImageFactory alloc] init];

        self.incomingBubbleImageData = [bubbleFactory incomingMessagesBubbleImageWithColor:[UIColor jsq_messageBubbleLightGrayColor]];
        self.outgoingBubbleImageData = [bubbleFactory outgoingMessagesBubbleImageWithColor:[UIColor jsq_messageBubbleGreenColor]];

        _messages = [NSMutableArray array];
        _avatars = [NSMutableDictionary dictionary];
        _users = [NSMutableDictionary dictionary];


    }
    return self;
}

- (void)addMessages:(JSQMessage *)message {
    NSParameterAssert(message != nil);
    NSParameterAssert(![message isKindOfClass:[JSQMessage class]]);

    [_messages addObject:message];
}

- (void)joinUsers:(NSString *)userID displayName:(NSString *)displayName {
    NSParameterAssert(userID != nil);
    NSParameterAssert(displayName != nil);

    [_users setObject:displayName forKey:userID];
}

- (void)joinUsersAvatar:(NSString *)userID complete:(UIImage * (^)(void))complete {
    NSParameterAssert(userID != nil);
    NSParameterAssert(complete != nil);

    JSQMessagesAvatarImage *userAvatar = [JSQMessagesAvatarImageFactory avatarImageWithImage:complete() diameter:kJSQMessagesCollectionViewAvatarSizeDefault];
    [_avatars setObject:userAvatar forKey:userID];
}

- (void)joinUsersAvatar:(NSString *)userID image:(UIImage *)image {
    NSParameterAssert(userID != nil);
    NSParameterAssert(image != nil);
    
    JSQMessagesAvatarImage *userAvatar = [JSQMessagesAvatarImageFactory avatarImageWithImage:image diameter:kJSQMessagesCollectionViewAvatarSizeDefault];
    [_avatars setObject:userAvatar forKey:userID];
}


- (void)clearData {
    [_messages removeAllObjects];
    [_avatars removeAllObjects];
    [_users removeAllObjects];
}

@end
